/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kreig133.analytic.classes;

import com.kreig133.analytic.interfaces.ViewDataHandler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 *
 * @author C.C.-fag
 */
public class Differentiator implements ViewDataHandler {
    private ViewDataHandler previous;

    public Differentiator(ViewDataHandler previous) {
        this.previous = previous;
    }

    @Override
    public Map<Double, Double> getProcessedData() throws Exception {
        Map<Double, Double> temp = previous.getProcessedData();

        List<Double> list = new ArrayList<Double>();
        list.addAll(temp.keySet());
        Collections.sort(list);
        for(int i = list.size()-1; i>0; i--){
            temp.put(list.get(i), temp.get(list.get(i))-temp.get(list.get(i-1)));
        }
        temp.put(list.get(0), temp.get(list.get(1)));
        
        return temp;
    }

}
